extends Label

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	print('Lable=========_ready=========')
	# 当前节点的父节点为Node，也就是main.gd
	print(get_parent().add(1,2))
	self.text = "Hello Godot!!" # Replace with function body.
	
	# 通过访问根节点查找其它节点s
	var logo = get_tree().get_root().find_child("Sprite2D_Logo", true, false)
	print(logo)
	
	# 全局的信号绑定
	EventBus.new_points.connect(_add_new_points)

func _add_new_points():
	print("$$$$$$$add new point event at label")

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float):
	#print(delta)
	return delta

# GUI控件的操作（对特定 GUI 控件操作做出反应，Mouse的filter不能为Ignore）
func _gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
			print("我已被点击 D:")
			self.text = "Hello Player"
			
	# 将事件消息消化，不会再触发_unhandled_input
	self.accept_event()

# 判断是否点击在控件上
func _has_point(point: Vector2) -> bool:
	return Rect2(Vector2.ZERO, size).has_point(point)

# 输入操作（有输入事件时会被调用。输入事件会沿节点树向上传播，直到有节点将其消耗。）
func _input(event: InputEvent) -> void:
	#print('event' + event.as_text())
	pass
	
# 事件如果没有被accept_event,则触发
func _unhandled_input(event: InputEvent) -> void:
	#print('unhandled event' + event.as_text())
	if event is InputEventKey:
		match event.as_text_keycode():
			KEY_LEFT:
				if event.pressed:
					start_moving_left()
				else: # key released
					stop_moving_left()
			KEY_RIGHT:
				if event.pressed:
					start_moving_right()
				else:
					stop_moving_right()
			KEY_Z:
				pass
			KEY_X:
				pass
			KEY_C:
				pass
			KEY_SPACE:
				pass
			KEY_DOWN:
				pass
			KEY_ESCAPE:
				pass

func start_moving_left():
	pass
	
func stop_moving_left():
	pass
	
func start_moving_right():
	pass
	
func stop_moving_right():
	pass
